package aynu.hd.Hotel.Service.Impl;

import aynu.hd.Hotel.Dao.roomDao;
import aynu.hd.Hotel.Dao.scheduleDao;
import aynu.hd.Hotel.Service.roomService;
import aynu.hd.pojo.Room;
import aynu.hd.pojo.Schedule;
import aynu.hd.pojo.User;
import aynu.hd.pojo.v_room_info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class roomServiceImpl implements roomService {
    @Autowired
    roomDao roomDao;
    @Autowired
    scheduleDao scheduleDao;

    //根据类型查找房间
    @Transactional
    @Override
    public List<Room> queryRoomByType(String roomType) {
        return roomDao.queryRoomByType(roomType);
    }

    //进入房间详情页面
    @Transactional
    @Override
    public Room queryRoomById(String room_id) {
        return roomDao.queryRoomById(room_id);

    }

    //查看房间是否被用户收藏
    @Override
    @Transactional
    public String queryCollectRoomByUser(User user, String room_id) {
        String[] splits = user.getUser_collect().split("@");
        for (String split : splits) {
            if (split.equals(room_id)) {
                return "TRUE";
            }
        }
        return "FALSE";
    }

    //查看房间评价
    @Transactional
    @Override
    public List<Schedule> queryRoomComment(String room_id) {
        return scheduleDao.queryRoomComment(room_id);
    }

    //收藏最多的房间
    @Transactional
    @Override
    public List<Room> queryRoomCollectMany() {
        return roomDao.queryRoomCollectMany();
    }

    //我的收藏(房间)
    @Transactional
    @Override
    public List<Room> environment(User user) {
        String[] splits = user.getUser_collect().split("@");
        return roomDao.queryRoomCollectByUser(splits);
    }

    //查看预定房间
    @Transactional
    @Override
    public List<Schedule> queryScheduleRoom(User user) {
        return scheduleDao.queryScheduleRoom(user.getUser_id());
    }

    //评论页面(根据房间id查找房间信息)
    @Transactional
    @Override
    public Schedule queryRoomCommentById(Schedule schedule) {
        return scheduleDao.queryScheduleById(schedule.getSchedule_id().toString());
    }

    //评论房间
    @Transactional
    @Override
    public void addComment(Schedule schedule) {
        scheduleDao.addComment(schedule);
    }

    //收藏最多的豪华套房信息
    @Transactional
    @Override
    public List<Room> queryRoomByCollect() {
        return roomDao.queryRoomByCollect();
    }

    //收藏最多的房间
    @Transactional
    @Override
    public List<Room> queryRoomByCollect1() {
        return roomDao.queryRoomByCollect1();
    }

    //销售最多的房间
    @Transactional
    @Override
    public List<v_room_info> queryRoomByCollect2() {
        return roomDao.queryRoomByCollect2();
    }
}
